<template>
  <div>
    <el-container>
      <el-header>Header</el-header>
      <el-container>
        <el-aside width="220px">
          <div class="菜单">
            <el-row class="tac">
              <el-col >
                <el-menu router
                         default-active="2"
                         class="el-menu-vertical-demo"
                         @open="handleOpen"
                         @close="handleClose">
                  <el-submenu index="1">
                    <template slot="title">
                      <i class="el-icon-location"></i>
                      <span>个人中心</span>
                    </template>
                    <el-menu-item index="/ks">我的信息</el-menu-item>
                    <el-menu-item index="/tz">通知中心</el-menu-item>
                    <el-menu-item index="/gz">我的关注</el-menu-item>
                    <el-menu-item index="ls">观看历史</el-menu-item>
                  </el-submenu>
                </el-menu>
              </el-col>
            </el-row>
          </div>
          <div class="菜单">
            <el-row class="tac">
              <el-col >
                <el-menu router
                    default-active="2"
                    class="el-menu-vertical-demo"
                    @open="handleOpen"
                    @close="handleClose">
                  <el-submenu index="2">
                    <template slot="title">
                      <i class="el-icon-video-camera-solid"></i>
                      <span>我的直播间</span>
                    </template>
                    <el-menu-item index="/kb">开播设置</el-menu-item>
                    <el-menu-item index="/xx">直播间信息</el-menu-item>
                    <el-menu-item index="/pk">PK设置</el-menu-item>
                  </el-submenu>
                </el-menu>
              </el-col>
            </el-row>
          </div>
          <div class="菜单">
            <el-row class="tac">
              <el-col >
                <el-menu router
                    default-active="2"
                    class="el-menu-vertical-demo"
                    @open="handleOpen"
                    @close="handleClose">
                  <el-submenu index="1">
                    <template slot="title">
                      <i class="el-icon-video-camera-solid"></i>
                      <span>直播间信息</span>
                    </template>
                    <el-menu-item index="/zl">数据总览</el-menu-item>
                    <el-menu-item index="/tj">礼物统计</el-menu-item>
                    <el-menu-item index="/ph">消费排行</el-menu-item>
                  </el-submenu>
                </el-menu>
              </el-col>
            </el-row>
          </div>
        </el-aside>

        <el-main>
          <div class="标题">
            <h>直播设置</h>
          </div>
          <div class="底部说明">
            使用第三方软件开播的用户点击开始直播后获取rtmp地址和推流码。
          </div>
          <el-card class="box-card">
            <div slot="header" class="clearfix">
          <span>
            <el-row >
         <el-avatar :size="80" :src=useravatar></el-avatar>
        </el-row>
            <div class="名字">{{nickname}}</div>
             <div class="idu">
               <i class="el-icon-user"></i>
          直播间id：1234512
        </div>
            <div class="正式会员">
              正式会员
            </div>
            <div class="实名认证">
              实名认证
            </div>
          </span>
            </div>
            <div class="我的直播间地址">
              我的直播间地址：
              <br>
              <el-button style="margin-top:5px;padding: 3px 0" type="text">https://www.kesion.com/zhibojiekou/47308</el-button>
            </div>
          </el-card>
          <el-card class="box-card">
            <el-form :model="dynamicValidateForm" ref="dynamicValidateForm" label-width="100px" class="demo-dynamic">
              <el-form-item
                  prop="liveTitle"
                  label="房间标题"
                  :rules="[
      { required: true, message: '请输入房间标题', trigger: 'blur' },
    ]">
                <el-input v-model="dynamicValidateForm.liveTitle"></el-input>
              </el-form-item>
              <el-form-item
                  prop="liveAbstract"
                  label="房间描述"
                  :rules="[
      { required: true, message: '请输入房间描述', trigger: 'blur' },
    ]">
                <el-input v-model="dynamicValidateForm.liveAbstract"></el-input>
              </el-form-item>
              <el-form-item
                  prop="liveTags"
                  label="房间标签">
                <el-input v-model="dynamicValidateForm.liveTags"></el-input>
              </el-form-item>
              你的rtmp地址:{{getLiveInfo.data.rtmpPushUrl}}
              <el-form-item>
                <el-button type="primary" @click="uploadArticle">开始直播</el-button>
              </el-form-item>
              <div class="底部说明-1">
                每次重新开播，请在这里复制新的rtmp地址和直播码到你的直播软件中
                <br>
                当推流过程中发生卡顿，可以尝试重新复制rtmp地址到你的直播软件中，如果仍然无法解决，请联系客服。
                <br>
                开通直播即代表同意富吾号使用协议，请勿上传和直播色情、暴力、反动信息！
              </div>
            </el-form>

          </el-card>
          <el-card class="box-card">
            <el-col span="3" class="标题小">
              直播封面:
            </el-col>
            <el-upload
                class="avatar-uploader"
                action="https://jsonplaceholder.typicode.com/posts/"
                :show-file-list="false"
                :on-success="handleAvatarSuccess"
                :before-upload="beforeAvatarUpload">
              <img v-if="liveCover" :src="liveCover" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon"></i>
            </el-upload>
            <div class="底部说明-2">
              仅支持 JPG格式，文件大小≤2M，建议尺寸1280*720，比例16：9。无法上传图片？尝试使用普通模式
            </div>
          </el-card>
          <el-card class="box-card">
            <el-col span="3" class="标题小">
              开播公告:
            </el-col>
            <el-input
                type="textarea"
                :rows="2"
                placeholder="请输入内容"
                v-model="textarea">
            </el-input>
          </el-card>
        </el-main>
      </el-container>
    </el-container>
    <div>
    </div>
  </div>
</template>

<script>
export default {
  name: "ks",
  data() {
    return {
      nickname: '',
      textarea: '',
      dynamicValidateForm: {
        idUser: 133,
        liveTitle:"JAVA JVM讲解",
        liveAbstract:"JVM 牛逼",
        liveCover: "https://img2.baidu.com/it/u=3355464299,584008140&fm=26&fmt=auto&gp=0.jpg",
        liveTags: "股票",

      },
      getLiveInfo:{
        msg:'',
        data:{
          rtmpPushUrl:'',
          idLive:'',
          isPublished:'',
          anchorUserId:'',
          allowMic:'',
        },
      },
      queryByIdUser: {
        idUser: window.sessionStorage.getItem("idUser")
      }

    }
  },
  created() {
    this.init()
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
    handleAvatarSuccess(res, file) {
      this.liveCover = URL.createObjectURL(file.raw);
    },
    beforeAvatarUpload(file) {
      const isJPG = file.type === 'image/jpeg';
      const isLt2M = file.size / 1024 / 1024 < 2;

      if (!isJPG) {
        this.$message.error('上传头像图片只能是 JPG 格式!');
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 2MB!');
      }
      return isJPG && isLt2M;
    },

    async init(){
        const {data: res} = await this.$http.get('http://39.102.76.217:8082/getuserbasicinfobyid', {
          params:this.queryByIdUser
        })
        this.nickname=res.nickname
        this.useravatar=res.useravatar
        this.userarticleandfuheadlinenumbers=res.userarticleandfuheadlinenumbers
        this.uservideonumbers=res.uservideonumbers
        this.userthumbups=res.userthumbups
        this.userfollows=res.userfollows
        this.userfollowers=res.userfollowers
    },
    async uploadArticle() {
      console.log(this. dynamicValidateForm.idUser)
      const {data: res} = await this.$http.post("http://39.102.76.217:8084/live/startlive", qs.stringify(this.dynamicValidateForm),{headers: {'Content-Type':'application/x-www-form-urlencoded'}});
      console.log(res)

      // const {data: res} = await this.$http.get(serverUrl+"/live/startlive",{
      //   params:this.queryByIdUser
      // })
      this.msg=res.msg
      this.getLiveInfo.data.rtmpPushUrl=res.data.rtmpPushUrl
      this.getLiveInfo.data.idLive=res.data.idLive
      this.getLiveInfo.data.isPublished=res.data.isPublished
      this.getLiveInfo.data.anchorUserId=res.data.anchorUserId
      this.getLiveInfo.data.allowMic=res.data.allowMic
    },
    // async getLiveInfo(){
    //
    // },
}
}


</script>

<style>
body{ background-color:#EEEEEE}
.text {
  font-size: 14px;
}
.box-card {
  float:right;
  margin-right:3%;
  margin-left:3%;
  width:94%;
  margin-bottom: 5%;
}
.底部说明{
  font-color: #d9d9d9;
  font-size:xx-small;
  margin-bottom:0%;
  margin-left:50%;
}
.底部说明-1{
  float:bottom;
  text-align: left;
  font-color: #d9d9d9;
  font-size:xx-small;
  margin-bottom:2%;
  margin-left:5%;
  color:#888888;

}
.菜单
{
  margin-left:3%;
}
.标题
{
  position:relative;
  font-size:x-large;
  top:-20px;
  float:left;
  margin-left:3%;
}
.头像{
  position:relative;
  width:14%;
  height:auto;
  margin-left:2%;
  margin-top:2%;
  margin-bottom: 2%;
  float: left;
}
.名字 {
  position: absolute;
  top:230px;
  left:310px;
  font-size:large;
  float:left;
  margin-left:8%;
}
.idu{
  position: absolute;
  top:237px;
  left:550px;
  font-size:x-small;
  color:#8c939d;
}
.标题
{
  position:relative;
  font-size:x-large;
  top:-20px;
  float:left;
  margin-left:3%;
}
.正式会员
{
  padding:2px;
  position: absolute;
  top:234px;
  color:#8c939d;
  border-radius:2px;
  left:720px;
  border: 1px solid #8c939d;
  font-size:xx-small;
}
.实名认证
{
  padding:2px;
  position: absolute;
  top:234px;
  color:#8c939d;
  border-radius:2px;
  left:782px;
  border: 1px solid #8c939d;
  font-size:xx-small;
}
.我的直播间地址
{
  position:relative;
  text-align: left;
  padding-left:2%;
  font-size:small;
}
.标题小{
  font-size:large;
  margin-bottom: 1%;
  margin-top:1%;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 178px;
  height: 178px;
  line-height: 178px;
  text-align: center;
}
.avatar {
  width: 178px;
  height: 178px;
  display: block;
}
.avatar-uploader
{
  position:relative;
  top:40px;
  left:-50px;
}
.底部说明-2{
  text-align: left;
  top:40px;
  font-color: #d9d9d9;
  font-size:xx-small;
  margin-bottom:2%;
  margin-left:5%;
  color:#888888;
}
</style>
